package cn.iocoder.yudao.module.book.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.book.controller.app.vo.AppBookReadingProgramReqVO;
import cn.iocoder.yudao.module.book.controller.app.vo.AppBookReadingProgramRespVO;
import cn.iocoder.yudao.module.book.service.app.AppBookReadingProgramService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bookReadingProgram")
public class AppReadingProgramController {


    @Resource
    private AppBookReadingProgramService bookReadingProgramService;

    @GetMapping("/list/{type}")
    @Operation(summary = "查询计划列表")
    public CommonResult<List<AppBookReadingProgramRespVO>> getBookReadingProgramList(@PathVariable String type) {
        return CommonResult.success(bookReadingProgramService.getBookReadingProgramList(type));
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "根据计划ID查询计划详情")
    public CommonResult<AppBookReadingProgramRespVO> getBookReadingProgramById(@PathVariable Long id) {
        return CommonResult.success(bookReadingProgramService.getBookReadingProgramById(id));
    }

    @PostMapping("/create")
    @Operation(summary = "创建计划")
    public CommonResult<Long> createBookReadingProgram(@Validated @RequestBody AppBookReadingProgramReqVO createReqVO) {
        return CommonResult.success(bookReadingProgramService.createBookReadingProgram(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新计划")
    public CommonResult<Boolean> updateBookReadingProgram(
        @Validated @RequestBody AppBookReadingProgramReqVO updateReqVO) {
        bookReadingProgramService.updateBookReadingProgram(updateReqVO);
        return CommonResult.success(true);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除计划")
    public CommonResult<Boolean> deleteBookReadingProgram(@PathVariable Long id) {
        bookReadingProgramService.deleteBookReadingProgram(id);
        return CommonResult.success(true);
    }
}
